package com.heer.gymnasium.module.article.views;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.heer.amap.utils.ToastUtil;
import com.heer.gymnasium.R;
import com.heer.gymnasium.api.ResponseData.ApiResponse;
import com.heer.gymnasium.api.callback.BaseCallback;
import com.heer.gymnasium.base.BaseActivity;
import com.heer.gymnasium.module.article.beans.ArticleResponseBean;
import com.heer.gymnasium.module.login.views.LoginActivity;

import butterknife.BindView;
import butterknife.OnClick;
import butterknife.OnFocusChange;
import butterknife.OnTextChanged;
import retrofit2.Call;
import retrofit2.Response;

/**
 * 评论
 * Created by zy on 2018/2/26.
 */

public class AddArticleReplyActivity extends BaseActivity {
    private final static int RES_ID_ROOT = R.layout.layout_evaluate;
    private final static int RES_ID_CONTENT_ET = R.id.layout_evaluate_content_et;
    private final static int RES_ID_COUNTER_TV = R.id.layout_evaluate_counter_tv;
    private final static int RES_ID_SUBMIT_TV = R.id.layout_evaluate_submit_tv;

    @BindView(RES_ID_CONTENT_ET)
    EditText etContent;
    @BindView(RES_ID_COUNTER_TV)
    TextView tvCounter;

    private AddArticleReplyActivity $this;

    @Override
    protected void init() {
        super.init();
        $this = this;
        setContentView(RES_ID_ROOT);
    }

    @Override
    protected void initView() {
        super.initView();
        titleUtils.setTitleText("评论");
    }

    @OnTextChanged(RES_ID_CONTENT_ET)
    public void onContentTextChange() {
        tvCounter.setText(etContent.getText().length() + "/150");
    }

    @OnClick(RES_ID_SUBMIT_TV)
    public void doSubmit(){
        String id = getIntent().getStringExtra(EXTRA_ID);
        mAppHelper.apiService().getAddArticleReply(id,etContent.getText().toString()).enqueue(new BaseCallback<ApiResponse<String>>() {
            @Override
            public void onSuccess(Call<ApiResponse<String>> call, Response<ApiResponse<String>> response) {
                ToastUtil.show($this,response.body().getMsg());
                $this.finish();
            }
        });
    }

    public static void startActivity(Context context, String id) {
        Intent mIntent = new Intent(context, AddArticleReplyActivity.class);
        mIntent.putExtra(EXTRA_ID, id);
        context.startActivity(mIntent);
    }
}
